package com.youka.bussiness.common.utils;

import com.youka.bussiness.common.base.BaseException;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.util.*;

/**
 * 日期工具类
 */
public class DateUtil {

    /**
     * 获取当月的第一天
     *
     * @return
     */
    public static final String getFirstMonthDay() {
        LocalDate localDate = LocalDate.now();
        LocalDate with = localDate.with(TemporalAdjusters.firstDayOfMonth());
        String firstDay = with + " 00:00:00";
        return firstDay;
    }

    /**
     * 获取本周第一天
     *
     * @param num 0本周，1下周，-1上周，依次类推
     * @return
     */
    public static final String getFirstWeekDay(int num) {
        LocalDate localDate = LocalDate.now().plusWeeks(num);
        LocalDate with = localDate.with(DayOfWeek.MONDAY);
        String firstDay = with + " 00:00:00";
        return firstDay;
    }

    /**
     * 获取某月最后一天
     *
     * @return
     */
    public static final int getLastDayOfMonth() {
        LocalDate today = LocalDate.now().withMonth(Integer.parseInt(getMM()));
        //某月的最后一天
        LocalDate lastDay = today.with(TemporalAdjusters.lastDayOfMonth());
        return lastDay.getDayOfMonth();
    }


    /**
     * 获取某月最后一天,可查去年(-1去年,0今年,1明年,以此类推)
     *
     * @return
     */
    public static final int getLastDayOfMonth(int month, int year) {
        LocalDate localDatew = LocalDate.now().plusYears(year).withMonth(month);
        //某月的最后一天
        LocalDate lastDay = localDatew.with(TemporalAdjusters.lastDayOfMonth());
        return lastDay.getDayOfMonth();
    }

    /**
     * 获取某年的开始日期
     *
     * @param offset 0今年，1明年，-1去年，依次类推
     * @return
     */
    public static LocalDate getYearStart(int offset) {
        return LocalDate.now().plusYears(offset).with(TemporalAdjusters.firstDayOfYear());
    }


    /**
     * 获取今天的零点时间戳
     *
     * @return
     */
    public static long getTodayZero() {
        long current = System.currentTimeMillis();
        long zero = current / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
        return zero;
    }

    public static long stringToLong(String item) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = simpleDateFormat.parse(item);
            Long ts = date.getTime() / 1000;
            return ts;
        } catch (Exception e) {
            return 0;
        }
    }

    /**
     * 获取某个时间戳所在的零点时间戳
     */
    public static long getTodayZero(Long current) {
        long zero = current / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
        return zero;
    }

    /**
     * 获取这个月的第一天时间戳
     */
    public static long getMouthZero() {
        Calendar cal = Calendar.getInstance();
        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
        //本月的第一天时间搓
        return cal.getTimeInMillis();
    }

    /**
     * 获取今年第一天时间戳
     */
    public static long getYearZero() {
        Calendar currCal = Calendar.getInstance();
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, currCal.get(Calendar.YEAR));
        return calendar.getTime().getTime();
    }


    /**
     * 获取当前日期和时间 格式 yyyyMMdd HH:mm:ss
     *
     * @return
     */
    public static String getCurrentDate() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(new Date());
    }

    /**
     * 获取当前日期和时间
     *
     * @param format 格式
     * @return
     */
    public static String getCurrentDate(String format) {
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        return formatter.format(new Date());
    }

    /**
     * 获取当前日期和时间
     *
     * @param date 格式的日期
     * @return
     */
    public static String getCurrentDate(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(date);
    }

    /**
     * 获取日期字符串
     *
     * @return
     */
    public static String getDate() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        return formatter.format(new Date());
    }

    /**
     * 获取日期字符串
     *
     * @param format 格式
     * @return
     */
    public static String getDate(String format) {
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        return formatter.format(new Date());
    }

    /**
     * 获取日期字符串
     *
     * @param date 格式日期
     * @return
     */
    public static String getDate(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        return formatter.format(date);
    }

    /**
     * @return
     */
    public static String getMouth() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        return sdf.format(new Date());
    }

    /**
     * 获取日期字符串
     *
     * @return
     */
    public static String getMM() {
        SimpleDateFormat formatter = new SimpleDateFormat("MM");
        return formatter.format(new Date());
    }

    /**
     * 获取时间字符串
     *
     * @return
     */
    public static String getTime() {
        SimpleDateFormat formatter = new SimpleDateFormat("HHmmss");
        return formatter.format(new Date());
    }

    /**
     * 获取时间字符串
     *
     * @param format 格式
     * @return
     */
    public static String getTime(String format) {
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        return formatter.format(new Date());
    }

    /**
     * 获取当前年度字符串
     *
     * @return
     */
    public static String getNowYear() {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
        return formatter.format(new Date());
    }

    /**
     * 获取当前月度字符串
     *
     * @return
     */
    public static String getNowMonth() {
        SimpleDateFormat formatter = new SimpleDateFormat("MM");
        return formatter.format(new Date());
    }

    /**
     * 获取当前月度字符串
     *
     * @return
     */
    public static String getNowDay() {
        SimpleDateFormat formatter = new SimpleDateFormat("dd");
        return formatter.format(new Date());
    }

    /**
     * 获取当前时间字符串
     *
     * @param date
     * @return
     */
    public static String getNowHour(Date date) {
        SimpleDateFormat formatter = new SimpleDateFormat("HH");
        return formatter.format(date);
    }

    /**
     * 时间搓转换成时间类型
     *
     * @param time 时间戳
     * @return
     * @throws Exception
     */
    public static Date stampToDate(long time) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String d = sdf.format(time);
        Date date = sdf.parse(d);
        return date;
    }

    /**
     * 时间搓转换成时间类型
     *
     * @param time   时间戳
     * @param format 格式
     * @return
     * @throws Exception
     */
    public static Date stampToDate(long time, String format) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String d = sdf.format(time);
        Date date = sdf.parse(d);
        return date;
    }

    /**
     * 将时间戳转换字符串时间
     *
     * @param time 时间戳
     * @return
     */
    public static String stampToStrDate(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(time);
        return sdf.format(date);
    }

    /**
     * 将时间戳转换字符串时间
     *
     * @param time 时间戳
     * @return
     */
    public static String stampToStrDate(long time, String format) {
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date date = new Date(time);
        return sdf.format(date);
    }

    /**
     * 精确日期
     *
     * @param date
     * @return
     */
    public static Date getAccurateDate(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.set(Calendar.MILLISECOND, 0);
        return c.getTime();
    }

    /**
     * 将String类型转成Date类型
     *
     * @param dateStr
     * @param format  转换类型
     * @return
     * @throws Exception
     */
    public static Date strToDate(String dateStr, String format) throws Exception {
        SimpleDateFormat df = new SimpleDateFormat(format);
        Date date = df.parse(dateStr);
        return date;
    }

    /**
     * 将String类型转成Date类型,默认格式yyyy-MM-dd HH:mm:ss
     *
     * @param dateStr
     * @return
     * @throws Exception
     */
    public static Date strToDate(String dateStr) throws Exception {
        return strToDate(dateStr, "yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 将String类型转成long类型,默认格式yyyy-MM-dd HH:mm:ss
     *
     * @param dateStr
     * @return
     * @throws Exception
     */
    public static long getMillis(String dateStr) throws Exception {
        return strToDate(dateStr, "yyyy-MM-dd HH:mm:ss").getTime();
    }

    /**
     * 获取时间戳，将日期对象转换为时间戳类型。
     *
     * @return
     */
    public static long dateToStamp(String str) throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(str);
        long ts = date.getTime();
        return ts;
    }

    /**
     * 获取时间戳，将日期对象转换为时间戳类型。
     *
     * @param date
     * @return
     */
    public static Timestamp getTimestamp(Date date) {
        return new Timestamp(date.getTime());
    }

    /**
     * 获取时间戳，将当前日期转换为时间戳类型。
     *
     * @return Timestamp 时间戳
     */
    public static long getTimestamp() {
        return System.currentTimeMillis();
    }

    /**
     * 当前日期延后多少天
     *
     * @param day 天数
     * @return
     */
    public static String addDate(int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis() + ((long) day) * 24 * 3600 * 1000);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(calendar.getTime());
    }

    /**
     * 当前日期延后多少天
     *
     * @param day 天数
     * @return
     */
    public static String addDateString(int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis() + ((long) day) * 24 * 3600 * 1000);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        return df.format(calendar.getTime());
    }

    /**
     * 获取上个月的
     *
     * @return
     */
    public static String getLastMonth() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date); // 设置为当前时间
        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1); // 设置为上一个月
        date = calendar.getTime();
        String accDate = format.format(date);
        return accDate;
    }

    /**
     * 当前日期延后多少天
     *
     * @param day 天数
     * @return
     */
    public static String addDateDay(int day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis() + ((long) day) * 24 * 3600 * 1000);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        return df.format(calendar.getTime());
    }

    /**
     * 当前日期提前多少天
     *
     * @param day 天数
     * @return
     */
    public static String subDate(int day, String format) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis() - ((long) day) * 24 * 3600 * 1000);
        SimpleDateFormat df = new SimpleDateFormat(format);
        return df.format(calendar.getTime());
    }

    /**
     * 指定日期提前多少天
     *
     * @param day 天数
     * @return
     */
    public static String stringDateAdd(int day, String dateString) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = sdf.parse(dateString);
            Calendar cl = Calendar.getInstance();
            cl.setTime(date);
            cl.add(Calendar.DATE, day);
            String temp = sdf.format(cl.getTime());
            return temp;
        } catch (Exception e) {
            throw new BaseException("时间转换异常");
        }
    }

    public static String stringString() {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
            return simpleDateFormat.format(new Date());
        } catch (Exception e) {
            throw new BaseException("时间转换异常");
        }

    }

    public static String stringToString(String temp) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date date = sdf.parse(temp);

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
            return simpleDateFormat.format(date);
        } catch (Exception e) {
            throw new BaseException("时间转换异常");
        }

    }


    /**
     * 获取前几个月月份
     *
     * @param mouth
     * @return
     * @throws Exception
     */
    public static ArrayList<String> getBeforeMouth(int mouth) throws Exception {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, -mouth);
        //六个月前
        String before_six = c.get(Calendar.YEAR) + "-" + c.get(Calendar.MONTH);
        ArrayList<String> result = new ArrayList<String>();
        // 格式化为年月
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(sdf.parse(before_six));
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
        max.setTime(sdf.parse(sdf.format(new Date())));
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
        Calendar curr = min;
        while (curr.before(max)) {
            result.add(sdf.format(curr.getTime()));
            curr.add(Calendar.MONTH, 1);
        }
        return result;
    }

    /**
     * 日期加上多少月后的日期
     *
     * @param now   当前时间
     * @param month 后延的月数
     * @return
     */
    public static Date dateAddMonth(Date now, int month) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        calendar.add(Calendar.MONTH, month);
        return calendar.getTime();
    }

    /**
     * 获取毫秒
     *
     * @param date 时间
     * @return
     */
    public static long getMillis(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getTimeInMillis();
    }

    /**
     * 获得 这周的第一天
     *
     * @return
     */
    public static Date getWeekFirstDay() throws Exception {
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Calendar calendar = Calendar.getInstance();
        //得到当天是这周的第几天
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        //减去dayOfWeek,得到第一天的日期，因为Calendar用０－６代表一周七天，所以要减一
        calendar.add(Calendar.DAY_OF_WEEK, -(dayOfWeek - 1));
        String beginTime1 = datef.format(calendar.getTime()) + " 00:00:00";
        Date firstDateOfWeek = dateFormat.parse(beginTime1);
        return firstDateOfWeek;
    }

    /**
     * 获得这周的最后一天
     *
     * @return
     */
    public static Date getWeekLastDay() throws Exception {
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Calendar calendar = Calendar.getInstance();
        //得到当天是这周的第几天
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        //每周7天，加6，得到最后一天的日子
        calendar.add(Calendar.DAY_OF_WEEK, 7 - dayOfWeek);
        String endTime1 = datef.format(calendar.getTime()) + " 23:59:59";
        Date lastDateOfWeek = dateFormat.parse(endTime1);
        return lastDateOfWeek;
    }

    /**
     * 获得这个月的第一天
     *
     * @return
     */
    public static Date getMonthFirstDay() throws Exception {
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Calendar c = Calendar.getInstance();
        c.add(Calendar.MONTH, 0);
        c.set(Calendar.DAY_OF_MONTH, 1);
        //设置为1号,当前日期既为本月第一天
        String beginTime1 = datef.format(c.getTime()) + " 00:00:00";
        Date firstDateOfWeek = dateFormat.parse(beginTime1);
        return firstDateOfWeek;
    }

    /**
     * 获取今年年第一天日期
     *
     * @return Date
     */
    public static Date getYearFirst() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy");
        int year = Integer.parseInt(format.format(new Date()));
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.set(Calendar.YEAR, year);
        Date currYearFirst = calendar.getTime();
        return currYearFirst;
    }


    /**
     * 获得这个月的最后一天
     *
     * @return
     */
    public static Date getThisMonthLastDay() throws Exception {
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
        String endTime1 = datef.format(ca.getTime()) + " 23:59:59";
        Date lastDateOfWeek = dateFormat.parse(endTime1);
        return lastDateOfWeek;
    }

    /**
     * 获取某年某月的最后一天
     *
     * @param year
     * @param month
     * @return
     */
    public static String getLastDay(int year, int month) {
        Calendar cal = Calendar.getInstance();
        //设置年份
        cal.set(Calendar.YEAR, year);
        //设置月份
        cal.set(Calendar.MONTH, month - 1);
        //获取某月最大天数
        int lastDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        //设置日历中月份的最大天数
        cal.set(Calendar.DAY_OF_MONTH, lastDay);
        //格式化日期
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String lastDayOfMonth = sdf.format(cal.getTime());
        return lastDayOfMonth;
    }

    /**
     * 判断今天是星期几
     *
     * @return
     * @throws ParseException
     */
    public static int checkDate() {
        Calendar calendar = Calendar.getInstance();
        Date date = new Date();
        calendar.setTime(date);
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        return dayOfWeek;
    }

    /**
     * 计算两个日期之间的间隔
     *
     * @param sDate
     * @param eDate
     * @return
     * @throws Exception
     */
    public static List<String> dateInterval(String sDate, String eDate) throws Exception {
        List<String> days = new ArrayList<String>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date sDay = dateFormat.parse(sDate);
        Date eDay = dateFormat.parse(eDate);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sDay);
        while (sDay.compareTo(eDay) <= 0) {
            days.add(dateFormat.format(calendar.getTime()));
            calendar.add(Calendar.DAY_OF_MONTH, 1);
        }
        return days;
    }

    /**
     * 计算两个月之间的月份
     *
     * @param sDate
     * @param eDate
     * @return
     * @throws Exception
     */
    public static List<String> monthInterval(String sDate, String eDate) throws Exception {
        ArrayList<String> months = new ArrayList<String>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
        Calendar sMonth = Calendar.getInstance();
        Calendar eMonth = Calendar.getInstance();
        sMonth.setTime(dateFormat.parse(sDate));
        sMonth.set(sMonth.get(Calendar.YEAR), sMonth.get(Calendar.MONTH), 1);
        eMonth.setTime(dateFormat.parse(eDate));
        eMonth.set(eMonth.get(Calendar.YEAR), eMonth.get(Calendar.MONTH), 2);
        while (sMonth.compareTo(eMonth) <= 0) {
            months.add(dateFormat.format(sMonth.getTime()));
            sMonth.add(Calendar.MONTH, 1);
        }
        return months;
    }

    /**
     * 当前日期向前推day天
     *
     * @param day
     * @return
     */
    public static List<String> backDay(int day) {
        List<String> pastDaysList = new ArrayList<String>();
        for (int i = 1; i <= 7; i++) {
            pastDaysList.add(getPastDate(i));
        }
        return pastDaysList;
    }

    public static String getPastDate(int past) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String result = format.format(today);
        return result;
    }


    /**
     * 获取指定日期后的第N天
     *
     * @param localDate 日期
     * @param days      天数
     * @return 指定日期后的第N天
     */
    public static LocalDate getNextNDay(LocalDate localDate, long days) {
        return localDate.with(temporal -> temporal.plus(days, ChronoUnit.DAYS));
    }

    /**
     * localdate -- 转string
     */
    public static String getNextStringDay(LocalDate localDate, long days) {

        LocalDate date = localDate.with(temporal -> temporal.plus(days, ChronoUnit.DAYS));
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String dateStr = date.format(fmt);
        return dateStr;
    }

    /**
     * localdate -- yue
     */
    public static String getNextStringMouth(LocalDate localDate, int days) {

        LocalDate date = localDate.with(temporal -> temporal.plus(days, ChronoUnit.MONTHS));
        DateTimeFormatter fmt = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String dateStr = date.format(fmt);
        return dateStr;
    }


    /**
     * 获取指定日期后的第N天
     *
     * @param days 天数
     * @return 指定日期后的第N天
     */
    public static String getNextNDayTime(String time, long days) {
        LocalDateTime now = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:ss:mm"));
        return now.minusDays(days).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:ss:mm"));
    }

    public static String localToString(LocalDate localDate) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String dateStr = localDate.format(df);
        return dateStr;
    }

    public static LocalDate stringToLocal(String localDate) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate dateParam = LocalDate.parse(localDate, df);
        return dateParam;
    }

    public static LocalDateTime stringToLocalTime(String localDate) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime dateParam = LocalDateTime.parse(localDate, df);
        return dateParam;
    }

    public static String loctostring(LocalDateTime time) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String localTime = df.format(time);
        return localTime;
    }


    public static String loctostringTime(LocalDateTime time) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String localTime = df.format(time);
        return localTime;
    }

    public static void main(String[] args) throws Exception {
//        System.out.println(loctostring(LocalDateTime.now()));
//        System.out.println(stringToLocalTime("2021-01-01 16:39:09"));

        System.out.println(getLastDayOfMonth());
//        System.out.println(getNextStringMouth(LocalDate.now(), 3));
    }

}